package cm.studapp.fragments;

import cm.studapp.R;
import cm.studapp.database.DbManager;
import cm.studapp.helpers.TimeHelper;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.LinearLayout;
import android.widget.ScrollView;

public class SemesterSelect extends DialogFragment implements OnClickListener {

	private View myView;
	private DatePicker initSem;
	private DatePicker endSem;
	@Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the Builder class for convenient dialog construction
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LayoutInflater inflater = getActivity().getLayoutInflater();
        
        myView =  inflater.inflate(R.layout.create_schedule_sem_sel, null);
        LinearLayout ll =(LinearLayout)((ScrollView) myView).getChildAt(0);
         
        initSem = (DatePicker)ll.getChildAt(2);
        endSem = (DatePicker)ll.getChildAt(4);
        //Listener de Botones:
        builder.setView(myView)
               .setPositiveButton("ok",this);
        
        // Create the AlertDialog object and return it
        return builder.create();
    }

	public static DialogFragment newInstance() {
		// TODO Auto-generated method stub
		SemesterSelect aux = new SemesterSelect();
		
		return aux;
	}

	@Override
	public void onClick(DialogInterface arg0, int arg1) {
		// TODO Auto-generated method stub
		TimeHelper th = new TimeHelper();
		DbManager db = new DbManager(getActivity());
		db.insertSemester(th.DatePickerToEpoch(initSem), th.DatePickerToEpoch(endSem));
		
		
	}
	
}
